'use strict';

const Controller = require('egg').Controller;

class FinancingController extends Controller {
  async create() {
    const { ctx } = this
    const { form = {} } = ctx.request.body
    const create = {
      form,
    }

    await ctx.model.Financings.create(create)
    ctx.body = create
  }

  async delete() {
    const { ctx } = this
    const { id } = ctx.params
    await ctx.model.Financings.destroy({
      where: {
        id
      }
    })
    ctx.body = { id }
  }

  async list() {
    const { ctx } = this
    const list = await ctx.model.Financings.findAll()

    ctx.body = {
      list
    }
  }

  async show() {
    const { ctx } = this
    const {id} = ctx.params
    ctx.body = await ctx.model.Financings.findOne({where: {id}})
  }
}

module.exports = FinancingController;
